CFNETTOOLS
CFNETTOOLS is a suite of Internet Protocol (IP) tools that enable ColdFusion MX developers to access common Internet protocols. While the most common protocols—HTTP and e-mail protocols (SMTP and POP3 primarily)—are both well supported in ColdFusion, some others are not. The CFNETTOOLS suite looks to offer this additional functionality.
CFNETTOOLS covers the following protocols/Internet tools:
- Domain Naming Service: As the networked dynamic database of domain name information, DNS is something we frequently use, even if we don't see it happen. Through DNS, we obtain the IP address of a computer at a given domain, find the domain that is mapped to a specified IP address, or even find out where the mail server is located for a particular domain.
- Finger: This is a protocol used to find user information on a specified server, which might contain contact information (e-mail, etc.) or even logon status depending on the server and its configuration.
- Time (Simple Network Time Protocol or SNTP): This Internet time protocol allows us to check times off of different servers worldwide.
- Whois: We have all done web-based Whois searches to find out who the owner of a specific domain name is. Whois information can also be accessed directly through this protocol.
Installing CFNETTOOLS
Note: CFNETTOOLS requires that your ColdFusion server is running on JVM version 1.4 or higher.
It's relatively straightforward to install CFNETTOOLS:
- In the ZIP file, extract the contents of the /WEB-INF/lib folder to the WEB-INF/lib folder in your ColdFusion installation. In stand-alone mode, this is cfmx_root/wwwroot/WEB-INF/. In the J2EE edition, this is server_root/WEB-INF.
- Install the files in the /tags folder to your ColdFusion tags folder.
- Install the optional test.cfm file for testing purposes if you wish.
- Restart the ColdFusion server to register the Java classes.
Using the CFNETTOOLS Suite
CFNETTOOLS is architected using Java as the underlying engine. The core Java classes make the network calls. You have a choice of calling on these classes directly or calling on the ColdFusion custom tags.
Note that all of these tags may throw a "Connection timed out" error if there is a timeout during the network request.
CF_DNSLookup
CF_DNSLookup is no doubt the most invaluable tool in the CFNETTOOLS suite because DNS information can be highly relevant in numerous application development scenarios. There are basically three actions to the CF_DNSLookup tag: getIP, which returns the IP address for a specified host; getHost, which returns the host name for a specified IP address; and getRecord, which allows you to pass the specific type of DNS record to access. The following types of records are supported: A, NS, CNAME, SOA, PTR, MX, TXT, HINFO, AAAA, NAPTR, SRV, IN, and HS. You can find more information about DNS at www.dns.net/dnsrd/.
Code example:
<cf_dnslookup name="IP" action="getIP" address="www.veraison.info">
CF_Finger
The Finger User Information Protocol is used to find out information about users for a particular machine or domain. This information generally varies from server to server depending on the type and quantity of information they expose using this protocol. One useful method for using Finger is to verify e-mails. However, keep in mind that many servers today do not have Finger activated. You can find more information about Finger at www.faqs.org/rfcs/rfc1288.html.
Code example:
<cf_finger name="fingerstuff" server="mit.edu" user="Rachmaninoff">
CF_Whois
The Referral Whois Protocol is a protocol that allows you to obtain the contact information of the owner of a domain name. Using this component, you can now obtain this information dynamically. Additionally, and lesser known, is the ability to query handles and other information from the Whois provider. CF_Whois supports entering the query directly, which means the more you understand Whois queries, the more you will get out of this tag. You can find more information about the Whois specification at www.faqs.org/rfcs/rfc1714.html.
Whois servers include whois.networksolutions.com, arin.net, and whois.ripe.net.
Code example:
<cf_whois name="whois" server="whois.networksolutions.com" query="domain=veraison.com">
CF_Time
Using this component you can quickly obtain a string that represents the current time. The Simple Network Time Protocol (SNTP) provides this information and you can specify the server from which you wish to retrieve the time. Keep in mind that there are numerous different formats that the time value will be returned in, so make sure your application parses the correct format if you wish to move the date into a CF-readable date. You can find more information about SNTP at www.faqs.org/rfcs/rfc2030.html.
Time servers include time.nist.gov, ntp1.fau.de, tock.gpsclock.com, and navobs1.usnogps.navy.mil.
Code example:
<cf_time name="time" server="time.nist.gov">
Using the Java Library Directly
You can access all the functionality listed in the previous tags using the core CFNETTOOLS Java classes—both within ColdFusion MX or in any J2EE application server. The javadoc of these classes is included in the DevNet Resource Kit and defines the available methods, the required arguments, and what type of information is returned. The included test.cfm file contains ColdFusion calls to all these objects for you to start with.
Code example:
<cfscript>
timeObj =
createobject("java","com.macromedia.NetTools.Time");
theTime = timeObj.getRemoteTime("time.nist.gov");
</cfscript>
The CFNETTOOLS Tag APIs
Use the CFNETTOOLS tag library to call on a number of IP-related protocols and programs and return their results to your ColdFusion application.
cf_dnslookup
Retrieves Domain Name Services information, including domain names, IP addresses, mail exchangers, and other information.
Syntax:
<cf_dnslookup action = "action" address = "ip_or_hostname" name = "variablename" nameserver = "nameserver" type = "recordtype">
| Attribute | Req/Opt | Default | Description |
|---|---|---|---|
| action | Optional | getIP |
getIP returns the IP address based on the host name passed getHost returns the host name based on the IP address passed getRecord returns the type record based on the address specified |
| address | Required | n/a | Either the IP address or host name on which to perform the lookup |
| name | Required | n/a | Name for the variable that contains the results of the DNS lookup |
| nameserver | Required if action = "getRecord" | n/a | Name server on which to look up the record; for other actions, cf_dnslookup uses the default DNS server specified by the machine |
| type | Required if action = "getRecord" | n/a | Type of DNS record to look up; acceptable types are A, NS, CNAME, SOA, PTR, MX, TXT, HINFO, AAAA, NAPTR, SRV, IN, and HS |
cf_finger
Syntax:
<cf_finger name = "variablename" server = "servername" user = "user">
| Attribute | Req/Opt | Default | Description |
|---|---|---|---|
| name | Required | n/a | Name of the variable to be returned by the tag call |
| server | Required | n/a | Domain name, server name, or IP address from which to retrieve the Finger information |
| user | Required | n/a | A username, last name, first name, or other information about who is being "fingered" |
cf_whois
Retrieves Whois information for a domain from the specified name server.
Syntax:
<cf_whois name = "variablename" server = "servername" query = "whois_query">
| Attribute | Req/Opt | Default | Description |
|---|---|---|---|
| name | Required | n/a | Name of the variable to be returned by the tag call |
| server | Required | n/a | Whois server to query |
| query | Required | n/a | Whois query: Basic domain Whois searches take the form of domain=domainname.com ; to query a handle, use handle=handleValue |
cf_time
Retrieves time information (as a string) from the server specified using the SNTP protocol.
Syntax:
<cf_time name = "variablename" server = "servername">
| Attribute | Req/Opt | Default | Description |
|---|---|---|---|
| name | Required | n/a | Name of the variable to be returned by the tag call (this is a string, not a date format) |
| server | Required | n/a | SNTP server to query |